package com.xhwl.data.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.xhwl.common.dto.cent.sdata.RoleDetailDTO;
import com.xhwl.common.dto.cent.sdata.RoleGrantDTO;
import com.xhwl.common.dto.cent.sdata.RoleOrgStructureDTO;
import com.xhwl.common.dto.cent.sdata.RoleTypeDTO;
import com.xhwl.common.enums.config.RoleTypeEnum;
import com.xhwl.common.pojo.AbstractAccount;
import com.xhwl.common.pojo.ResultJson;
import com.xhwl.common.pojo.cent.sdata.Account;
import com.xhwl.common.pojo.cent.sdata.AdminAccount;
import com.xhwl.common.pojo.cent.sdata.Role;
import com.xhwl.common.query.cent.sdata.RoleQuery;
import com.xhwl.data.pojo.RoleTypeQuery;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author:
 * @create: 2020-11-25
 **/
@RestController
public interface IRoleService extends IService<Role> {


    /**
     * 判断账号角色身份
     *
     * @param accountId
     * @return
     */
    @RequestMapping(value = "/role-service/account-role-type", method = RequestMethod.POST)
    RoleTypeDTO getAccountRoleType(@RequestPart("accountId") Integer accountId);


    /**
     * 批量判断账号角色身份
     *
     * @param accountId
     * @return
     */
    Map<Integer, RoleTypeDTO> getAccountRoleTypeBatch(List<Integer> accountId);

    /**
     * 批量新增初始化的内置普通角色
     *
     * @param roles
     */
    void initializeRoleBatch(List<Role> roles);


    /**
     * 创建角色
     *
     * @param roleGrantDTO
     * @return
     */

    @RequestMapping(value = "/role-service/create-role", method = RequestMethod.POST)
    ResultJson<Integer> createRole(@RequestPart("roleGrantDTO") RoleGrantDTO roleGrantDTO);

    /**
     * 修改角色   权限 /包括关联的APP表
     *
     * @param operateAccount
     * @param roleGrantDTO
     * @return
     */
    @RequestMapping(value = "/role-service/update-role", method = RequestMethod.POST)
    ResultJson updateRole(@RequestPart("account") AbstractAccount operateAccount, @RequestPart("roleGrantDTO") RoleGrantDTO roleGrantDTO);

	/**
	 * 运维平台修改角色
	 * @param role
	 * @return
	 */
	@RequestMapping(value = "/role-service/update-by-admin", method = RequestMethod.POST)
	ResultJson updateByAdmin(@RequestPart("role") Role role);


    /**
     * 删除角色
     *
     * @param operateAccount
     * @param roleId
     * @return
     */
    @RequestMapping(value = "/role-service/delete-role", method = RequestMethod.POST)
    ResultJson deleteRole(@RequestPart(value = "operateAccount", required = false) Account operateAccount, @RequestPart("roleId") Integer roleId);

    /**
     * 动态获取 角色list 分页
     *
     * @param operateAccount
     * @param page
     * @param roleQuery
     * @return
     */
    @RequestMapping(value = "/role-service/get-rolePageList", method = RequestMethod.POST)
    Page<Role> getRolePageList(@RequestPart(value = "operateAccount", required = false) Account operateAccount, @RequestPart("page") Page page, @RequestPart("roleQuery") RoleQuery roleQuery);

    /**
     * 动态获取 角色list 不分页
     *
     * @param operateAccount
     * @param roleQuery
     * @return
     */
    @RequestMapping(value = "/role-service/get-roleList", method = RequestMethod.POST)
    List<Role> getRoleList(@RequestPart(value = "operateAccount", required = false) Account operateAccount, @RequestPart("roleQuery") RoleQuery roleQuery);

    /**
     * 动态查找单个角色
     *
     * @param roleQuery
     * @return
     */
    @RequestMapping(value = "/role-service/get-one", method = RequestMethod.POST)
    Role getRole(@RequestPart(value = "roleQuery") RoleQuery roleQuery);

    /**
     * 根据账号id获取角色list
     *
     * @param accountId
     * @return
     */
    @RequestMapping(value = "/role-service/list-by-account", method = RequestMethod.POST)
    List<Role> getRoleListByAccountId(@RequestPart(value = "accountId")Integer accountId);

    /**
     * 是否包含物业角色
     * @param accountId
     * @return
     */
    @RequestMapping(value = "/role-service/estate-role-check", method = RequestMethod.POST)
    ResultJson isContainEstateRole(@RequestPart(value = "accountId") Integer accountId);


    /**
     * 根据主键id 获取角色信息
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/role-service/get-by-id", method = RequestMethod.POST)
    Role getRoleById(@RequestPart(value = "id") Integer id);

    /**
     * 根据角色id获取 挂钩的账号的数量
     *
     * @return
     */
    @RequestMapping(value = "/role-service/role-account-count", method = RequestMethod.POST)
    List<RoleDetailDTO> getAccountCountByRoleId(@RequestPart(value = "roleIds", required = false) List<Integer> roleIds);

    /**
     * 获取角色类型 下拉选择器
     *
     * @return
     */
    ResultJson getRoleType();

    List<Map<String, Object>> getRoleType(RoleTypeQuery roleTypeQuery);

    /**
     * 角色验重
     *
     * @param roleGrantDTO
     * @return
     */
    @RequestMapping(value = "/role-service/role-verify", method = RequestMethod.POST)
    Boolean roleExistChecking(@RequestPart("roleGrantDTO") RoleGrantDTO roleGrantDTO);


    /**
     * 是否是超管
     *
     * @param accountId
     * @return
     */
    @RequestMapping(value = "/role-service/super-manager-check", method = RequestMethod.POST)
    boolean isSuperManager(@RequestPart("accountId") Integer accountId);


    /**
     * 角色名验重
     *
     * @param roleGrantDTO
     * @return
     */
    ResultJson roleNameExistCheck(@RequestPart("roleGrantDTO") RoleGrantDTO roleGrantDTO);


    /**
     * 创建角色 后台调用
     *
     * @param role
     * @return
     */
    @RequestMapping(value = "/role-service/create-role-admin", method = RequestMethod.POST)
    ResultJson createRoleAdmin(@RequestPart("role") Role role);

    /**
     * 创建角色
     *
     * @param role
     * @param adminAccount
     * @return
     */
    ResultJson createRoleAdminV2(RoleGrantDTO role, AdminAccount adminAccount);

    /**
     * 角色权限绑定
     *
     * @param id
     * @param permissionIds
     * @return
     */
    @RequestMapping(value = "/role-service/permission-bind", method = RequestMethod.POST)
    ResultJson permissionBind(@RequestPart("id") Integer id, @RequestPart("permissionIds") List<Integer> permissionIds);


    /**
     * 查询出普通内置角色ids
     *
     * @param industryIdList
     * @return
     */
    @RequestMapping(value = "/role-service/get-common-initRoles", method = RequestMethod.POST)
    List<Integer> getCommonInitializedRoles(@RequestPart("industryIdList") List<Short> industryIdList);


    /**
     * 查询出普通内置角色信息
     *
     * @param industryIdList
     * @return
     */
    List<Role> getCommonInitRoleDetail(List<Short> industryIdList);

    List<Integer> getSuperAdminRoles(List<Short> industryIdList);

    /**
     * 从角色list中提取出用于填充组织架构名称相关的map
     *
     * @param roleList
     * @return
     */
    RoleOrgStructureDTO getRoleOrgStructureData(List<Role> roleList);

    /**
     * 修改角色 功能权限校验  (单个)
     *
     * @param operateRoleType 当前登录账号的角色身份
     * @param oRole           即将修改的角色信息
     * @return
     */
    Boolean updateRoleCheck(RoleTypeEnum operateRoleType, Role oRole);

    /**
     * 删除角色 功能权限校验  (单个)
     *
     * @param operateRoleType 当前登录账号的角色身份
     * @param oRole           即将修改的角色信息
     * @return
     */
    Boolean deleteRoleCheck(RoleTypeEnum operateRoleType, Role oRole);

    /**
     * 修改角色 功能权限校验  (批量)
     *
     * @param operateRoleType 当前登录账号的角色身份
     * @param roles           即将修改的角色信息
     * @return
     */
    Map<Integer, Boolean> updateRoleCheckBatch(RoleTypeEnum operateRoleType, List<Role> roles);

    /**
     * 删除角色 功能权限校验  (批量)
     *
     * @param operateRoleType
     * @param roles
     * @return
     */
    Map<Integer, Boolean> deleteRoleCheckBatch(RoleTypeEnum operateRoleType, List<Role> roles);


    /**
     * 获取项目 所关联到的全部角色数据 ，包括反查企业角色、也支持扩展超管、普通内置角色
     *
     * @param industryId
     * @param projectIds
     * @param needCommonInitialized
     * @param needSuper
     * @return
     */
    List<RoleDetailDTO> getCurrentProjectRelatedList(Short industryId, List<Integer> projectIds, Boolean needCommonInitialized, Boolean needSuper);


    /**
     * 角色详情数据
     * @param industryId
     * @param roleId
     * @return
     */
    @RequestMapping(value = "/role-service/get-detail", method = RequestMethod.POST)
    RoleDetailDTO getDetail(@RequestPart("industryId") Short industryId, @RequestPart("roleId") Integer roleId);


    /**
     * 是否是企管
     * @param accountId
     * @return
     */
    boolean isEntManager(Integer accountId);

    /**
     * 是否是项管
     * @param accountId
     * @return
     */
    boolean isProjectManager(Integer accountId);

    boolean isOperationalManager(Integer accountId);

    @RequestMapping(value = "/role-service/get-common-init-roles", method = RequestMethod.POST)
    List<Map<String, Object>> getCommonInitRoleEnumList(Short industryId);


    /**
     * 内部使用 查询角色
     *
     * @param roleQuery
     * @return
     */
    @RequestMapping(value = "/role-service/view-list", method = RequestMethod.POST)
    List<Role> getList(@RequestPart("roleQuery") RoleQuery roleQuery);

    /**
     * 内部使用 分页查询角色
     *
     * @param operateAccount
     * @param page
     * @param roleQuery
     * @return
     */
    @RequestMapping(value = "/role-service/view-page-list", method = RequestMethod.POST)
    Page<Role> getPageList(@RequestPart(value = "operateAccount", required = false) Account operateAccount, @RequestPart("page") Page page, @RequestPart("roleQuery") RoleQuery roleQuery);


    /**
     * 获取平台下游客角色
     * @param industryId
     * @return
     */
    List<Role> getTouristRoleByIndustryId(Short industryId);


    ResultJson updateRoleAdminV2(RoleGrantDTO roleGrantDTO, AdminAccount adminAccount);

    Map<Integer, List<Role>> batchRoleMap(List<Integer> accountIds);
}
